package alg.list;

/**
 * @author:yuziji
 * @create: 2023-04-24 09:31
 */
public class ReverseList {
    public static void main(String[] args) {
        Node head = new Node(1);
        head.next = new Node(2);
        head.next.next = new Node(3);
        head.next.next.next = new Node(4);
//        head.printNode(head);
        Node node = reverseNode(head);
        node.printNode(node);
    }

    public static Node reverseNode(Node head){
        Node result = null;//最终返回的链表
        Node current = head;
        while(current!=null){
            Node temp = current.next;
            current.next = result;
            result = current;
            current = temp;
        }
        return result;
    }
}
